package com.gzw.dms.adapter;

import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gzw.dms.R;
import com.gzw.dms.bean.MessageInfo;
import com.gzw.dms.bean.UserInfo;
import com.jauker.widget.BadgeView;

import java.util.List;

/**
 * Created by Administrator on 2016/9/8.
 */
public class MessageAdapter  extends RecyclerView.Adapter {
    public static interface OnRecyclerViewListener {
        void onItemClick(int position);
        boolean onItemLongClick(int position);
    }
    private OnRecyclerViewListener onRecyclerViewListener;
    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }
    private static final String TAG = AbonrmalAdapter.class.getSimpleName();
    private List<MessageInfo> list;
    public MessageAdapter(List<MessageInfo> list) {
        this.list = list;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_messageadapter, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int i) {
        PersonViewHolder holder = (PersonViewHolder) viewHolder;
        holder.position = i;
        MessageInfo messageInfo = list.get(i);
        holder.ic_title.setText("标题:"+"   "+messageInfo.getOrderMsgTitle());

        holder.ic_senduser.setText("发送人:" + messageInfo.getSendUserName());
        holder.ic_time.setText("发送时间:" + messageInfo.getUpdatetime());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class PersonViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
        public View rootView;
        public TextView ic_title;
        public TextView ic_senduser;
        public TextView ic_time;

        public int position;
        public PersonViewHolder(View itemView) {
            super(itemView);
            ic_title = (TextView) itemView.findViewById(R.id.ic_title).findViewById(R.id.tv_name);
            ic_senduser = (TextView) itemView.findViewById(R.id.ic_senduser).findViewById(R.id.tv_name);
            ic_time = (TextView) itemView.findViewById(R.id.ic_time).findViewById(R.id.tv_name);
            rootView = itemView.findViewById(R.id.ll);
            rootView.setOnClickListener(this);
            rootView.setOnLongClickListener(this);
        }
        @Override
        public void onClick(View v) {
            if (null != onRecyclerViewListener) {
                onRecyclerViewListener.onItemClick(position);
            }
        }
        @Override
        public boolean onLongClick(View v) {
            if (null != onRecyclerViewListener) {
                return onRecyclerViewListener.onItemLongClick(position);
            }
            return false;
        }
    }
}
